package services

import (
	"encoding/json"
	"server/global"
	"server/internal/model"
)

var Config = new(config)

type config struct {
	model.Config
}

func (a config) GetConfig(group string) map[string]any {
	Db := global.GL_DB
	detail := model.Config{}
	Db.Model(&detail).Where("`group` =?", group).First(&detail)
	siteConfig := make(map[string]any)
	json.Unmarshal([]byte(detail.Value), &siteConfig)

	return siteConfig
}

func (a *config) WebConfig() map[string]any {
	data := make(map[string]any)
	data["web_config"] = a.GetConfig("basics")
	data["contact"] = a.GetConfig("contact")
	//var newsType []model.NewsType
	//Db := global.GL_DB
	//Db.Model(&newsType).Where("status = 1").Order("sort").Find(&newsType)
	//data["news_type"] = newsType
	return data
}
